package com.xxxx.yygh.msm.receiver;


import com.rabbitmq.client.Channel;
import com.xxxx.yygh.mq.constant.MqConst;
import com.xxxx.yygh.msm.service.MsmService;
import com.xxxx.yygh.vo.msm.MsmVo;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MsmReceiver {
    @Autowired
    private MsmService msmService;

    /**
     * 使用 mq进行监听  这是消费者
     * @param msmVo
     *
     */
    @RabbitListener(
            bindings = @QueueBinding(value = @Queue(value = MqConst.QUEUE_MSM_ITEM, durable = "true"),
                    exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_MSM),
                    key = {MqConst.ROUTING_MSM_ITEM}
            ))
    public void send(MsmVo msmVo, Message message, Channel channel){
        System.out.println("发送短信给用户啦~");
        System.out.println(msmVo.getPhone());
        msmService.send(msmVo.getPhone(),"1111");
    }

}